﻿using System;
using System.IO;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;

namespace PickGold.Nulls
{
	/// <summary>
	/// NullCollection
	/// </summary>
	public sealed class NullCollection : ICollection
	{
		/// <summary>
		/// 唯一实例
		/// </summary>
		public readonly static ICollection Value = new NullCollection();

		private NullCollection()
		{
			if (Value != null)
				throw new InvalidOperationException();
		}

		void ICollection.CopyTo(Array array, int index)
		{
		}

		int ICollection.Count
		{
			get
			{
				return 0;
			}
		}

		bool ICollection.IsSynchronized
		{
			get
			{
				return true;
			}
		}

		object ICollection.SyncRoot
		{
			get
			{
				return this;
			}
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return NullEnumerator.Value;
		}
	}

	/// <summary>
	/// NullCollection
	/// </summary>
	public sealed class NullCollection<T> : ICollection<T>
	{
		/// <summary>
		/// 唯一实例
		/// </summary>
		public readonly static ICollection<T> Value = new NullCollection<T>();

		private NullCollection()
		{
			if (Value != null)
				throw new InvalidOperationException();
		}

		void ICollection<T>.Add(T item)
		{
		}

		void ICollection<T>.Clear()
		{
		}

		bool ICollection<T>.Contains(T item)
		{
			return false;
		}

		void ICollection<T>.CopyTo(T[] array, int arrayIndex)
		{
		}

		int ICollection<T>.Count
		{
			get
			{
				return 0;
			}
		}

		bool ICollection<T>.IsReadOnly
		{
			get
			{
				return false;
			}
		}

		bool ICollection<T>.Remove(T item)
		{
			return false;
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			return NullEnumerator<T>.Value;
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return NullEnumerator<T>.Value;
		}
	}
}
